/*
 
functions

void        theme_ToggleTreeview +

void        theme_SetAppTitle( string ) +

void        theme_SetPageTitle( string)
void        theme_SetPageTitleSuffix( string )
void        theme_SetPageTitlePrefix( string )

void        theme_SetToolbarButtonText( string, string ) +
void        theme_SetToolbarImage( string, string ) +

void        theme_Resize +
void        theme_ResizeCustom +
void        theme_OnLoadCustom +
void        theme_SetCookie( string, string ) +
string      theme_GetCookie( string ) +
 
void        theme_SetTreeviewNodeText( string, string ) +
void        theme_SetTreeviewNodeBold(string ) +
void        theme_SetTreeviewSuffix( string, string ) +

integer     theme_GetContentWidth +
integer     theme_GetContentHeight +


 
*/

document.documentElement.onresizeend = theme_ResizeLayout;


var theme_curWidth = 0;
var theme_curX = 0;
var theme_newX = 0;
var theme_mouseButtonPos = "up";
var theme_bResizing = false;


function theme_SetPos(e)
{
    curEvent = ((typeof event == "undefined")? e: event);

    theme_mouseButtonPos = "down";
    theme_curX = curEvent.clientX;
    theme_curWidth = document.getElementById("theme_treeview").offsetWidth; // - document.getElementById("splitterBar").offsetWidth
}

function theme_GetPos(e){
    if( theme_mouseButtonPos == "down" )
    {
        curEvent = ((typeof event == "undefined")? e: event);
        theme_newX = curEvent.clientX;

        var pixelMovement = parseInt(theme_newX - theme_curX);

        var newWidth = parseInt(theme_curWidth + pixelMovement);
        //Enforce a minimum width.
        newWidth = ((newWidth < 15)? 15: newWidth);

        //Set the new width.
        document.getElementById("theme_treeview").style.width = newWidth + "px";

        //Set the new left of the splitter bar.
        document.getElementById("splitterBar").style.left = parseInt(document.getElementById("theme_treeview").offsetWidth) + "px";
        document.getElementById("theme_right_pane").style.left = parseInt(document.getElementById("theme_treeview").offsetWidth + document.getElementById("splitterBar").offsetWidth) + "px";
        document.getElementById("theme_right_pane").style.width = (document.documentElement.clientWidth - document.getElementById("theme_treeview").offsetWidth + document.getElementById("splitterBar").offsetWidth) + "px";


        //set the cookie
        theme_SetCookie("theme_treeview_width",newWidth);
    }
}



function theme_OnLoad()
{
    theme_ResizeLayout();
    

//alert(document.getElementById("theme_content").offsetHeight);

    if(typeof theme_OnLoadCustom == "function")
    {
        theme_OnLoadCustom();
    }
}
      

function theme_OnUnload()
{

    if(typeof theme_OnUnloadCustom == "function")
    {
        mxReturnVal = theme_OnUnloadCustom();
        return mxReturnVal;
    }
}
      
      

function theme_ResizeLayout()
{
    if (!theme_bResizing) // hack to make IE work
    {
        theme_bResizing=true;

        
        // Need to remember the scrolltop for when jumping to # tags after resize
        
        nScrollTop = document.getElementById("theme_content").scrollTop;
        
        nTopMargin = theme_GetTopMenuHeight() + theme_GetAppTitleHeight();
        nScreenHeight = document.documentElement.clientHeight;

        if (document.getElementById("theme_treeview"))
        {

            document.getElementById("theme_treeview").style.height = (nScreenHeight - nTopMargin) + "px";

            document.getElementById("theme_treeview").style.top = nTopMargin + "px"
            
        }

        if (document.getElementById("theme_title_bar"))
        {
            nTopMargin+=document.getElementById("theme_title_bar").offsetHeight;
        }

        if (document.getElementById("theme_toolbar"))
        {
            nTopMargin+=document.getElementById("theme_toolbar").offsetHeight;
        }

        nTVWidth = theme_GetApplicationOptionsWidth();

        if (document.getElementById("theme_StaticContent"))
        {
            nTopMargin+=document.getElementById("theme_StaticContent").offsetHeight;
            //document.getElementById("theme_StaticContent").style.width=(document.documentElement.clientWidth - nTVWidth) + "px";
            //document.getElementById("theme_StaticContent").style.left = (nTVWidth-3) + "px";
        }


        
                

        document.getElementById("theme_right_pane").style.width = (document.documentElement.clientWidth - nTVWidth) + "px";
        document.getElementById("theme_right_pane").style.left = (nTVWidth-theme_BorderWidth) + "px";
        
        document.getElementById("theme_content").style.height = (document.documentElement.clientHeight - nTopMargin) + "px"
        
        document.getElementById("theme_content").scrollTop = nScrollTop;
        
        
        if(typeof theme_ResizeCustom == "function")
        {
            theme_ResizeCustom();
        }
        

        theme_bResizing=false;
    }        
}

function theme_GetApplicationOptionsWidth()
{
    if (document.getElementById("theme_treeview"))
    {
        objOptions = document.getElementById("theme_treeview");
    
        if (objOptions.style.display!="none")
        {
            return objOptions.offsetWidth+theme_BorderWidth;
        }
        else
        {
            return 0;
        }
    }
    else
    {
        return 0;
    }
}

function theme_ResizeContent()
{
    // need treeview width as common
     
     nTVWidth = 0;
     
     if (document.getElementById("theme_treeview"))
     {
         if (document.getElementById("theme_treeview").style.display = "block")
         {

             nTVWidth = document.getElementById("theme_treeview").offsetWidth;
         }
     }

    document.getElementById("theme_content").style.width = (document.documentElement.clientWidth - nTVWidth) + "px";

}    

function theme_ResizeToolbar()
{
    // need treeview width as common
     
     nTVWidth = 0;
     
     if (document.getElementById("theme_treeview"))
     {
         if (document.getElementById("theme_treeview").style.display = "block")
         {

             nTVWidth = document.getElementById("theme_treeview").offsetWidth;
         }
     }
             
    if (document.getElementById("theme_toolbar"))
    {
        document.getElementById("theme_toolbar").style.width = (document.documentElement.clientWidth - nTVWidth) + "px";
    }
    
}

function theme_ResizeTitleBar()
{
    // need treeview width as common
     
     nTVWidth = 0;
     
     if (document.getElementById("theme_treeview"))
     {
         if (document.getElementById("theme_treeview").style.display == "block")
         {

             nTVWidth = document.getElementById("theme_treeview").offsetWidth;
         }
     }
             


     // work on each component separately.  Because they are absolutely positioned, we can make assumptions
     
     if (document.getElementById("theme_title_bar"))
     {
         document.getElementById("theme_title_bar").style.width = (document.documentElement.clientWidth - nTVWidth) + "px";
     }
}    
    


function theme_GetTreeviewWidth()
{
    if (document.getElementById("theme_treeview"))
    {
        return document.getElementById("theme_treeview").offsetWidth + document.getElementById("splitterBar").offsetWidth;
    }
    else
    {
        return 0;
    }
}


function theme_SetTreeviewWidth(nWidth)
{
    if (document.getElementById("theme_treeview"))
    {
        document.getElementById("theme_treeview").style.width=nWidth + "px";
    }
}
    
function theme_GetToolbarHeight()
{
    if (document.getElementById("theme_toolbar"))
    {
        return document.getElementById("theme_toolbar").offsetHeight;
    }
    else
    {
        return 0;
    }
}

function theme_SetToolbarLeft()
{
    if (document.getElementById("theme_toolbar"))
    {
        //document.getElementById("theme_toolbar").style.width = (document.documentElement.clientWidth - theme_GetTreeviewWidth() - 5) + "px";
        document.getElementById("theme_toolbar").style.left = (theme_GetTreeviewWidth() + 5) + "px"; 
    }
}

function theme_GetAppTitleHeight()
{
    if (document.getElementById("theme_app_title"))
    {
        // laborious...
        objTitle=document.getElementById("theme_app_title");
        objSplit=document.getElementById("theme_horizontal_split");

        nReturn=objTitle.offsetHeight + objSplit.offsetHeight;
        
        return nReturn;
    }
    else
    {
        return 0;
    }
}

function theme_GetTopMenuHeight()
{
    if (document.getElementById("theme_top_menu"))
    {
        objMenu=document.getElementById("theme_top_menu");
        return objMenu.offsetHeight;
    }
    else
    {
        return 0;
    }
}
    

function theme_SetCookie(sName, sValue)
{
    document.cookie = sName+"="+sValue+";path=/";
}

function theme_GetCookie(sName)
{
    var sString=sName + "=";
    var aCookies = document.cookie.split(';');
    for(var i=0;i < aCookies.length;i++)
    {
        var sTest = aCookies[i];
        while (sTest.charAt(0)==' ') sTest = sTest.substring(1,sTest.length);
        if (sTest.indexOf(sString) == 0)
        {
            return sTest.substring(sString.length,sTest.length);
        }
    }
    return null;
}

function theme_ToggleTreeview()
{
    objTV = document.getElementById("theme_treeview");
    if (typeof objTV != "undefined")
    {
        if (objTV.style.display == "none")
        {
            objTV.style.display = "block";
            theme_SetCookie("theme_treeview", "show");
            document.getElementById("theme_treeview_anchor").src = theme_sHideIcon;

            theme_ResizeLayout()
            //document.getElementById("theme_right_pane").style.left="231px";
            //document.getElementById("theme_right_pane").style.width= (document.documentElement.clientWidth - 234) + "px";
            

        }
        else
        {
            objTV.style.display = "none";
            theme_SetCookie("theme_treeview", "hidden");
            document.getElementById("theme_treeview_anchor").src = theme_sShowIcon;

            theme_ResizeLayout()
            //document.getElementById("theme_right_pane").style.left="0px";
            //document.getElementById("theme_right_pane").style.width="100%";
            //document.getElementById("theme_right_pane").style.width = (document.getElementById("theme_right_pane").offsetWidth - 5) + "px"
            
            
        }
    }
}

function theme_ToggleAppOptionList(nList)
{
    objAL = document.getElementById("theme_app_option_list_" + nList);

        if (objAL.style.display == "none")
        {
            objAL.style.display = "block";
            theme_SetCookie("theme_app_option_list_" + nList, "show");
            document.getElementById("theme_app_option_list_img_"+nList).src = theme_sOptionsHideIcon;
           

        }
        else
        {
            objAL.style.display = "none";
            theme_SetCookie("theme_app_option_list_" + nList, "hidden");
            document.getElementById("theme_app_option_list_img_"+nList).src = theme_sOptionsShowIcon;
            
        }
    
}

function theme_DisableToolbarButton( sButton )
{
    if (document.getElementById(sButton))
    {
        document.getElementById(sButton).className="theme_toolbar_disabled";
    }
    
}

function theme_EnableToolbarButton( sButton )
{
    if (document.getElementById(sButton))
    {
        document.getElementById(sButton).className="";
    }
    
}

function theme_SetToolbarButtonText( sButton, sText )
{
    if (document.getElementById(sButton+"_txt"))
    {
        document.getElementById(sButton+"_txt").innerHTML=sText;
    }
}

function theme_SetToolbarImage( sButton, sImg )
{
    if (document.getElementById(sButton+"_img"))
    {
        document.getElementById(sButton+"_img").src=sImg;
    }
}

function theme_SetTreeviewNodeText( sNode, sText )
{
    if (document.getElementById(sNode+"_txt"))
    {
        document.getElementById(sNode+"_txt").innerHTML=sText;
    }
}

function theme_SetTreeviewNodeSuffix( sNode, sText )
{
    if (document.getElementById(sNode+"_sfx"))
    {
        document.getElementById(sNode+"_sfx").innerHTML=sText;
    }
}


function theme_SetTreeviewNodeBold( sNode )
{
    if (document.getElementById(sNode+"_txt"))
    {
        document.getElementById(sNode+"_txt").style.fontWeight = "Bold";
    }
}
    
function theme_GetContentWidth()
{
    return document.getElementById("theme_content").offsetWidth;
}


function theme_GetContentHeight()
{
    return document.getElementById("theme_content").offsetHeight;
}


function theme_SetAppTitle( sText )
{
    if (document.getElementById("theme_app_title_text"))
    {
        document.getElementById("theme_app_title_text").innerHTML = sText;
    }
}

function theme_SetPageTitle( sText )
{
    if (document.getElementById("theme_title_text"))
    {
        document.getElementById("theme_title_text").innerHTML = sText;
    }
}
    
function theme_SetPageTitleSuffix( sText )
{
    if (document.getElementById("theme_title_suffix"))
    {
        document.getElementById("theme_title_suffix").innerHTML = sText;
    }
}

function theme_SetPageTitlePrefix( sText )
{
    if (document.getElementById("theme_title_prefix"))
    {
        document.getElementById("theme_title_prefix").innerHTML = sText;
    }
}


/*
         alert(nReturn);
        
        if (objMenu.style.borderBottomWidth.length!=0)
        {
            nReturn+=parseInt(objMenu.style.borderBottomWidth);
        }
        
        if (objMenu.style.borderTopWidth.length!=0)
        {
            nReturn+=parseInt(objMenu.style.borderTopWidth);
        }

        if (objTitle.style.borderBottomWidth.length!=0)
        {
            nReturn+=parseInt(objTitle.style.borderBottomWidth);
        }
        
        if (objTitle.style.borderTopWidth.length!=0)
        {
            nReturn+=parseInt(objTitle.style.borderTopWidth);
        }
        
        if (objSplit.style.borderBottomWidth.length!=0)
        {
            nReturn+=parseInt(objSplit.style.borderBottomWidth);
        }
        
        if (objSplit.style.borderTopWidth.length!=0)
        {
            nReturn+=parseInt(objSplit.style.borderTopWidth);
        }
        

*/